<?php
function to_utf($str) {
	return @iconv("windows-1251", "UTF-8//IGNORE", $str);
}


function get_random_string($len) {
	$result = "";
	$nums = "AEIKLMOUYS";
	$syms = "abcdefghijklmnopqrstuvwxyz";
	$sux = $nums.$syms;
	for ($i = 0; $i <= $len; $i++) {
		$num = rand(0, strlen($sux) - 1);
		$result .= $sux[$num];
	}
	return $syms[rand(0,strlen($syms) - 1)].$result;
}

function gennames() {
	$path = "logins/";
	$filename = $path."names.txt";
	$fd = fopen($filename, 'r');
	$n_arr = fread($fd, filesize($filename));
	fclose($fd);
	$n_arr = split("\n", $n_arr);

	$filename = $path."surnames.txt";
	$fd = fopen($filename, 'r');
	$s_arr = fread($fd, filesize($filename));
	fclose($fd);
	$s_arr = split("\n", $s_arr);

	$rnd_name    = $n_arr[rand(0, count($n_arr) - 1)];
	$rnd_surname = $s_arr[rand(0, count($s_arr) - 1)];
	$rnd_name    = urlencode(iconv("UTF-8", "windows-1251//IGNORE", $rnd_name));
	$rnd_surname = urlencode(iconv("UTF-8", "windows-1251//IGNORE", $rnd_surname));
	$arr['name']    = $rnd_name;
	$arr['surname'] = $rnd_surname;
	return $arr;
}

function eflush() {
	global $is_browser;
	if($is_browser) { ob_flush(); flush(); }
}


function db_init() {
	$dbcnx = @mysql_connect("localhost", "root", "qqq");
	mysql_query("SET NAMES utf8");
	@mysql_select_db("vknew", $dbcnx);
	return $dbcnx;
}


function search_infile($filename, $str_in_row, $str1 = "", $str2 = "", $row_number = 0) {
	if (($fd = fopen($filename, 'r')) !== FALSE) {
		$bufer = fread($fd, filesize($filename));
		fclose($fd);
		$bufer = split("\n", $bufer);
		for($i = 0; $i < count($bufer); $i++) {
			$tmp = strpos($bufer[$i], $str_in_row, 0);
			if($tmp !== FALSE) {
				$line = $bufer[$i+$row_number];
				if($str1) {
					$line = substr($line, strrpos($line, $str1, 0) + strlen($str1));
				}
				if($str2) {
					$line = substr($line, 0, strpos($line, $str2));
				}
				$line_arr[] = $line;
			}
		}
		if(isset($line_arr)) { return $line_arr; }
	} else {
		echo ">>>===CANT OPEN===<<< ".$filename."\n";
	}
}

function search_infile_left($filename, $str_in_row, $str1 = "", $str2 = "", $row_number = 0) {
	if (($fd = fopen($filename, 'r')) !== FALSE) {
		$bufer = fread($fd, filesize($filename));
		fclose($fd);
		$bufer = split("\n", $bufer);
		for($i = 0; $i < count($bufer); $i++) {
			$tmp = strpos($bufer[$i], $str_in_row, 0);
			if($tmp !== FALSE) {
				$line = $bufer[$i+$row_number];
				if($str1) {
					$line = substr($line, strpos($line, $str1, 0) + strlen($str1));
				}
				if($str2) {
					$line = substr($line, 0, strpos($line, $str2));
				}
				$line_arr[] = $line;
			}
		}
		if(isset($line_arr)) { return $line_arr; }
	} else {
		echo ">>>===CANT OPEN===<<< ".$filename."\n";
	}
}



function multicurl($d, $sleep_time = 1500000, $mm_sleep_time = 25000) {
	global $is_debug, $i_prx, $prx_all_arr, $prx_max, $max_proxy_failed, $user_agent, $timeout;
	if(isset($d)) {
		$t_max = count($d);
		$ft    = 1; # failed trigger
		while($ft != 0) {
			################################
			usleep($sleep_time);
			$t2 = 0;
			$mh = curl_multi_init();
			for($t = 0; $t < $t_max; $t++) {
				if($d[$t]['chk'] != 0) {
					$ch[$t2] = curl_init();
					curl_setopt($ch[$t2], CURLOPT_FAILONERROR,    TRUE);
					curl_setopt($ch[$t2], CURLOPT_FOLLOWLOCATION, TRUE);
					curl_setopt($ch[$t2], CURLOPT_RETURNTRANSFER, TRUE);
					curl_setopt($ch[$t2], CURLOPT_TIMEOUT,        $timeout);
					curl_setopt($ch[$t2], CURLOPT_USERAGENT,      $user_agent);
					curl_setopt($ch[$t2], CURLOPT_URL,            $d[$t]['url']);
					if(!empty($d[$t]['cuk'])) { curl_setopt($ch[$t2], CURLOPT_COOKIEJAR,  $d[$t]['cuk']);
					/*                        */curl_setopt($ch[$t2], CURLOPT_COOKIEFILE, $d[$t]['cuk']);  }
					if(!empty($d[$t]['prx'])) { curl_setopt($ch[$t2], CURLOPT_PROXY,      $d[$t]['prx']);
					/*                        */curl_setopt($ch[$t2], CURLOPT_PROXYTYPE,  CURLPROXY_HTTP); }
					if(!empty($d[$t]['pst'])) { curl_setopt($ch[$t2], CURLOPT_POST,       1);
					/*                        */curl_setopt($ch[$t2], CURLOPT_POSTFIELDS, $d[$t]['pst']);  }
					curl_multi_add_handle($mh, $ch[$t2]);
					$t2++;
				}
			}

			do {
				$n = curl_multi_exec($mh, $active);
				usleep($mm_sleep_time); # чтобы не грузить сразу проц
			} while($active > 0);

			$t2 = 0;
			for($t = 0; $t < $t_max; $t++) {
				if($d[$t]['chk'] != 0) {
					$res[$t] = curl_multi_getcontent($ch[$t2]);
					curl_multi_remove_handle($mh, $ch[$t2]);
					curl_close($ch[$t2]);
					if(strcmp($res[$t], "") != 0) {
						$fd = fopen($d[$t]['fnm'], "w");
						fwrite($fd, $res[$t]);
						fclose($fd);
					}
					$t2++;
				}
			}
			curl_multi_close($mh);

			################################ ОБРАБОТКА ДАННЫХ ######################################

			$ft = 0;
			for($t = 0; $t < $t_max; $t++) {
				if($d[$t]['chk'] != 0) {
					if($is_debug) {
						echo ">>> ".$t;
						echo " URL=".$d[$t]['url'];
						if(!empty($d[$t]['pst'])) { echo " POST=". $d[$t]['pst']; }
						if(!empty($d[$t]['prx'])) { echo " PROXY=".$d[$t]['prx']; }
						echo " ".date("Y-m-d H:i:s")."\t";
					}
					if(empty($res[$t])) {
						$ft = 1;
						if($is_debug) {	echo "---\n"; }
						if(!empty($d[$t]['prx'])) {
							$d[$t]['chk']++;
							if($d[$t]['chk'] <= $max_proxy_failed) {
								echo "failed trigger=".$d[$t]['chk']."\n";
							} else {
								if($i_prx < count($prx_all_arr) - 1) {
									$i_prx++;
								} else {
									echo "i_prx=".$i_prx." ";
									exit("proxy finished\n");
								}
								echo "failed trigger=".$d[$t]['chk']." CHANGING PROXY i_prx=".$i_prx."\n";
								$d[$t]['chk'] = 1;
								$d[$t]['prx'] = $prx_all_arr[$i_prx];
							}
						} # if(!empty($d[$t]['prx']))
					} else {      # if(strcmp($res[$t], "") == 0)
						$d[$t]['chk'] = 0;
						if($is_debug) {	echo "+++\n"; }
					}             # if(strcmp($res[$t], "") == 0)
				}  # if($nct[$t] == 1)
			}  # for($t = 0; $t < $t_max; $t++)
		}  # while($ft != 0)
		return $d;
	} else {
		exit("NO DATA!!!\n");
	}  #if(isset($d))
} # function multicurl(...);


function change_cookie($filename) {
	$fd = fopen($filename, "r");
	$bufer = fread($fd, filesize($filename));
	fclose($fd);
	$bufer = split("\n", $bufer);

	for($i=0; $i < count($bufer); $i++) {
		if(strpos($bufer[$i], "remixlang", 0) !== FALSE) {
			$bufer[$i]    = substr($bufer[$i], 0, (strlen($bufer[$i])-1))."3"; // set LANG to English
			$deleted      = substr($bufer[$i+2], strrpos($bufer[$i+2], "remixmid") + 9);
			$cookie_login = substr($bufer[$i+3], strrpos($bufer[$i+3], "remixemail") + 11);

			if(strcmp($deleted, "deleted") == 0) {
				echo $filename." --- deleted ---\n"; eflush();
			} else {
				echo $cookie_login." id=".$deleted."\n"; eflush();
			}

			$fd = fopen($filename, "w");
			for($i_w = 0; $i_w < count($bufer); $i_w++) {
				fwrite($fd, $bufer[$i_w]."\n");
			}
			fclose($fd);

			break;
		}
	}
}


function get_lmcookies($threads = 1) {
	global $temp_dir, $lcm_arr, $pcm_arr, $prx_arr;
	$total = count($lcm_arr);	//$total = 50;

	//print_r($prx_arr);
	for($l = 0; $l < $total; $l += $threads) {
		unset($d);
		for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++) {
			if(!is_dir($temp_dir.$lcm_arr[$l+$t])) { mkdir($temp_dir.$lcm_arr[$l+$t]); }
			$d[$t]['chk'] = 1;
			$d[$t]['url'] = "http://vkontakte.ru/login.php";
			$d[$t]['pst'] = "email=".$lcm_arr[$l+$t]."&pass=".$pcm_arr[$l+$t];
			//$d[$t]['prx'] = $prx_arr[$l+$t];
			$d[$t]['cuk'] = $temp_dir.$lcm_arr[$l+$t]."/cookie.txt";
			$d[$t]['fnm'] = $temp_dir.$lcm_arr[$l+$t]."/index.html";
		}

		$d = multicurl($d);
		
		for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++) {
			//$prx_arr[$l+$t] = $d[$t]['prx']; # нужно на тот случай, если прокси поменялся
			echo ($l + $t)."\t";
			change_cookie($d[$t]['cuk']);
			system("cp ".$d[$t]['cuk']." ".$temp_dir."lcm50/cookies_".($l + $t + 0).$lcm_arr[$l + $t].".txt");
		}
		
		//system("./chip.sh");
		//print_r($prx_arr);
	}
}


function get_smcookies($threads = 1) {
	global $temp_dir, $scm_arr, $spcm_arr;
	$total = count($scm_arr);	//$total = 50;

	for($l = 0; $l < $total; $l += $threads) {
		unset($d);
		for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++) {
			if(!is_dir($temp_dir."1search/".$scm_arr[$l+$t])) { mkdir($temp_dir."1search/".$scm_arr[$l+$t]); }
			$d[$t]['chk'] = 1;
			$d[$t]['url'] = "http://vkontakte.ru/login.php";
			$d[$t]['pst'] = "email=".$scm_arr[$l+$t]."&pass=".$spcm_arr[$l+$t];
			$d[$t]['cuk'] = $temp_dir."1search/".$scm_arr[$l+$t]."/cookie.txt";
			$d[$t]['fnm'] = $temp_dir."1search/".$scm_arr[$l+$t]."/index.html";
		}

		$d = multicurl($d);

		for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++) {
			echo ($l + $t)."\t";
			change_cookie($d[$t]['cuk']);
		}
	}
}


function get_rmcookies($threads = 1) {
	global $temp_dir, $rcm_arr, $rpcm_arr;
	$total = count($rcm_arr);	//$total = 50;

	for($l = 0; $l < $total; $l += $threads) {
		unset($d);
		for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++) {
			if(!is_dir($temp_dir."1real/".$rcm_arr[$l+$t])) { mkdir($temp_dir."1real/".$rcm_arr[$l+$t]); }
			$d[$t]['chk'] = 1;
			$d[$t]['url'] = "http://vkontakte.ru/login.php";
			$d[$t]['pst'] = "email=".$rcm_arr[$l+$t]."&pass=".$rpcm_arr[$l+$t];
			$d[$t]['cuk'] = $temp_dir."1real/".$rcm_arr[$l+$t]."/cookie.txt";
			$d[$t]['fnm'] = $temp_dir."1real/".$rcm_arr[$l+$t]."/index.html";
		}

		$d = multicurl($d);

		for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++) {
			echo ($l + $t)."\t";
			change_cookie($d[$t]['cuk']);
		}
	}
}


function get_mmcookies_durov($login, $p, $threads = 1) {
	global $obj_curl, $temp_dir;
	$total = count($login);	//$total = 50;

	for($l = 0; $l < $total; $l += $threads) {
		unset($obj_curl->mm_url, $obj_curl->mm_post, $obj_curl->mm_cookie, $obj_curl->mm_filename);

		for($t = 0; ( ($t < $threads) && (($l+$t) < $total) ); $t++) {
			if(!is_dir($temp_dir.$login[$l+$t])) { mkdir($temp_dir.$login[$l+$t]); }
			$obj_curl->mm_url[$t]          = "http://login.userapi.com/auth";
			$obj_curl->mm_proxy[$t]        = FALSE;
			$obj_curl->mm_post[$t]         = "site=2&id=0&fccode=0&fcsid=0&login=force&email=".$login[$l+$t]."&pass=".$p[$l+$t];
			$obj_curl->mm_cookie[$t]       = $temp_dir.$login[$l+$t]."/dcookie.txt";
			$obj_curl->mm_filename[$t]     = $temp_dir.$login[$l+$t]."/dindex.html";
		}

		$obj_curl->mm_method_main_curl(0);

		for($t=0; ( ($t < $threads) && (($l+$t) < $total) ); $t++) {
			change_cookie($obj_curl->mm_cookie[$t]);
		}
	}
}


function event_enter($login, $threads=20) {
	global $gid, $obj_curl, $temp_dir;
	$total = count($login);	//$total = 50;

	for($l = 0; $l < $total; $l += $threads) {
		unset($obj_curl->mm_url, $obj_curl->mm_post, $obj_curl->mm_cookie, $obj_curl->mm_filename);

		for($t=0; ( ($t < $threads) && (($l+$t) < $total) ); $t++) {
			$obj_curl->mm_url[$t]          = "http://vkontakte.ru/events.php?act=enter&gid=".$gid;
			$obj_curl->mm_proxy[$t]        = FALSE;
			$obj_curl->mm_post[$t]         = FALSE;
			$obj_curl->mm_cookie[$t]       = $temp_dir.$login[$l+$t]."/cookie.txt";
			$obj_curl->mm_filename[$t]     = $temp_dir.$login[$l+$t]."/evententer.html";
		}
		$obj_curl->mm_method_main_curl(0);
	}
}


function event_leave($login, $threads=20) {
	global $gid, $obj_curl, $temp_dir;
	$total = count($login);	//$total = 50;

	for($l = 0; $l < $total; $l += $threads) {
		unset($obj_curl->mm_url, $obj_curl->mm_post, $obj_curl->mm_cookie, $obj_curl->mm_filename);

		for($t=0; ( ($t < $threads) && (($l+$t) < $total) ); $t++) {
			$obj_curl->mm_url[$t]          = "http://vkontakte.ru/events.php?act=leave&gid=".$gid;
			$obj_curl->mm_proxy[$t]        = FALSE;
			$obj_curl->mm_post[$t]         = FALSE;
			$obj_curl->mm_cookie[$t]       = $temp_dir.$login[$l+$t]."/cookie.txt";
			$obj_curl->mm_filename[$t]     = $temp_dir.$login[$l+$t]."/eventleave.html";
		}
		$obj_curl->mm_method_main_curl(0);
	}
}


function get_durov($threads=1) {
	global $obj_curl, $temp_dir, $table;

	$dbcnx = db_init();
	$id_counter = 0;
	$id_result = mysql_query("SELECT id_vk, name, curr_time FROM `".$table."`");

	while($id_row = mysql_fetch_row($id_result)) {
		list($id_vk, $name, $curr_time)       = $id_row;
		$id_vk_arr    [$id_counter] = $id_vk;
		$name_arr     [$id_counter] = $name;
		$curr_time_arr[$id_counter] = $curr_time;
		$id_counter++;
	}

	for($i = 0; $i < $id_counter; $i++) {
		$obj_curl->mm_url     [0]     = "http://userapi.com/data?&act=profile&id=".$id_vk_arr[$i]."&sid=0c45a0b5ba5a841a9219e0a6f8f120f12beb1983784335f6e8dabf96";
		$obj_curl->mm_proxy   [0]     = FALSE;
		$obj_curl->mm_post    [0]     = FALSE;
		$obj_curl->mm_cookie  [0]     = $temp_dir."durov/dcookie.txt";
		$obj_curl->mm_filename[0]     = $temp_dir."durov/dindex.html";
		$obj_curl->mm_method_main_curl(0,25000);

		list($str) = file($obj_curl->mm_filename[0]);
		$str = substr($str, strpos($str,"\"cin\": \"")+8, 29);

		if($str == "Санкт-Петербург") {
			$tmp_query  = "INSERT INTO `".$table."-spb` (id, id_vk, flag, year, day, curr_time, send_time, name) VALUES ";
			$tmp_query .= "(NULL, '".$id_vk_arr[$i]."', '1', ";
			$tmp_query .= "NULL, NULL, ";
			$tmp_query .= "'$curr_time_arr[$i]', NULL, '$name_arr[$i]')";
			mysql_query($tmp_query);
			echo $i."\t".$id_vk_arr[$i]."\t".$name_arr[$i]."\t".$str."\n";
		} else {
			echo $i."\t".$id_vk_arr[$i]."\t".$name_arr[$i]."\n";
		}
	}
	mysql_close($dbcnx);
}


function change_info($path) {
	global $temp_dir;
	$d[0]['cuk'] = $path."cookie.txt";
	$is_mk = FALSE;
	#************************
	unset($d[0]['pst']);
	$d[0]['url'] = "http://vkontakte.ru/settings.php";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."settings_hash.html";
	$d = multicurl($d);
	list($hash)=search_infile($d[0]['fnm'], "hash", "value=\"", "\"");
	echo "settings hash=".$hash."\n";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."change_name.html";
	$names_arr = gennames();
	$d[0]['pst'] = "act=change_name&hash=".$hash."&nickname=&subm=1&first_name=".$names_arr['name']."&last_name=".$names_arr['surname'];
	if($is_mk) { $d[0]['pst'] = "act=change_name&hash=".$hash."&nickname=&subm=1&first_name=%CC%E8%F8%E0&last_name=%CA%EE%F2%EE%E2"; }
	$d = multicurl($d);
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."change_services.html";
	$d[0]['pst'] = "act=change_services&subm=1&news=1&audio=1&fave=1&matches=1&opinions=1&apps=1&questions=1&friendgroups=1&market=1";
	$d = multicurl($d);
	unset($d[0]['pst']);
	$d[0]['url'] = "http://vkontakte.ru/settings.php?act=privacy";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."settings_privacy_hash.html";
	$d = multicurl($d);
	list($hash)=search_infile($d[0]['fnm'], "hash", "value=\"", "\"");
	echo "settings privacy hash=".$hash."\n";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."change_privacy.html";
	$d[0]['pst'] = "act=change_privacy&subm=1&hash=".$hash."&group_privacy=0&event_privacy=1&pm_privacy=1&wall_privacy=1&friends_privacy=4&photo_privacy=1&graffiti_privacy=1&profile_privacy=1";
	$d = multicurl($d);
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."change_notify.html";
	$d[0]['pst'] = "act=change_notify&subm=1&friend_notify=1&pm_notify=1&wall_notify=1&photo_notify=1&group_notify=1&contest_notify=2";
	$d = multicurl($d);
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."change_fr_notify.html";
	$d[0]['url'] = "http://vkontakte.ru/settings.php?act=do_updates";
	$d[0]['pst'] = "subm=1&photos=on&videos=on&audios=on&notes=on&questions=on&status=on&groups=on&events=on&profile_info=on&photos_with=on&gifts=on";
	$d = multicurl($d);
	if($is_mk) {
		unset($d[0]['pst']);
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."matches_hash.html";
		$d[0]['url'] = "http://vkontakte.ru/matches.php";
		$d = multicurl($d);
		list($hash)=search_infile($d[0]['fnm'], "saveQuestion", "('", "')");
		echo "matches hash=".$hash."\n";
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."change_matches.html";
		$d[0]['url'] = "http://vkontakte.ru/matches.php";
		$d[0]['pst'] = "act=a_save&question=%D1%87%D1%82%D0%BE%D0%B1%D1%8B%20%D1%8F%20%D0%BF%D0%BE%D0%BC%D0%BE%D0%B3%20%D0%B2%D0%B0%D0%BC%20%D1%81%20%D0%BA%D0%BE%D0%BC%D0%BF%D1%8C%D1%8E%D1%82%D0%B5%D1%80%D0%BE%D0%BC&hash=".$hash;
		$d = multicurl($d);
		#************************
		unset($d[0]['pst']);
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."question_hash.html";
		$d[0]['url'] = "http://vkontakte.ru/questions.php?act=add_question";
		$d = multicurl($d);
		list($hash)=search_infile($d[0]['fnm'], "hash", "value=\"", "\"");
		echo "question hash=".$hash."\n";
		$d[0]['url'] = "http://vkontakte.ru/questions.php";
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."add_question.html";
		$d[0]['pst'] = "act=do_add_question&hash=".$hash."&message=%D5%EE%F2%E5%EB%E8+%E1%FB+%E2%FB%2C+%F7%F2%EE%E1%FB+%FF+%E2%E0%EC+%EF%EE%EC%EE%E3+%F1+%EA%EE%EC%EF%FC%FE%F2%E5%F0%EE%EC%3F&type=7";
		$d = multicurl($d);
	}
	#************************
	unset($d[0]['pst']);
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."pe_hash.html";
	$d[0]['url'] = "http://vkontakte.ru/profileEdit.php";
	$d = multicurl($d);
	list($hash)=search_infile($d[0]['fnm'], "hash", "value=\"", "\"");
	echo "pe hash=".$hash."\n";

	$d[0]['url'] = "http://vkontakte.ru/profileEdit.php";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."pe1.html";
	$d[0]['pst'] = "subm=1&hash=".$hash."&sex=2&status=6&status=6&with=0&bday_day=".rand(1, 28)."&bday_month=".rand(1, 12)."&bday_year=".rand(1970, 1992)."&bday_visibility=1&home_town=%D1%E0%ED%EA%F2-%CF%E5%F2%E5%F0%E1%F3%F0%E3&political=8&religion_name=%E2%E5%F0%FE+%E2+%F1%E5%E1%FF&religion_id=-1";
	if($is_mk) { $d[0]['pst'] = "subm=1&hash=".$hash."&sex=2&status=6&status=6&with=0&bday_day=1&bday_month=4&bday_year=1982&bday_visibility=1&home_town=%D1%E0%ED%EA%F2-%CF%E5%F2%E5%F0%E1%F3%F0%E3&political=8&religion_name=%E2%E5%F0%FE+%E2+%F1%E5%E1%FF&religion_id=-1"; }
	$d = multicurl($d);

	$d[0]['url'] = "http://vkontakte.ru/profileEdit.php?page=contacts";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."pe2.html";
	$d[0]['pst'] = "subm=1&hash=".$hash."&basic_country=1&basic_city=2&cmail=&privacyMail=1&privacyMPhone=1&privacyHPhone=1&privacyICQ=1&privacyAddress=0&mobile_phone=ask+me&home_phone=ask+me&icq=ask+me&website=&faddress=%C0%E4%F0%E5%F1+%F4%EE%F0%F3%EC%E0&fnick=";
	if($is_mk) { $d[0]['pst'] = "subm=1&hash=".$hash."&basic_country=1&basic_city=2&cmail=&privacyMail=1&privacyMPhone=0&privacyHPhone=0&privacyICQ=1&privacyAddress=0&mobile_phone=%F1%EF%F0%EE%F1%E8%F2%E5%2C+%E5%F1%EB%E8+%ED%F3%E6%E5%ED&home_phone=%F1%EF%F0%EE%F1%E8%F2%E5%2C+%E5%F1%EB%E8+%ED%F3%E6%E5%ED&icq=330320&website=http%3A%2F%2Fvkontakte.ru%2Fclub8493653&faddress=%C0%E4%F0%E5%F1+%F4%EE%F0%F3%EC%E0&fnick="; }
	$d = multicurl($d);

	$d[0]['url'] = "http://vkontakte.ru/profileEdit.php?page=address";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."pe3.html";
	$d[0]['pst'] = "subm=1&hash=".$hash."&addr_type1=10&addr_type1_other=%CA%E8%ED%EE%F2%E5%E0%F2%F0&addr_country1=1&addr_city1=2&addr_district1=128&addr_station1=170&addr_street1=291728&addr_street1_other=%CA%F3%EB%FC%F2%F3%F0%FB+%EF%F0.&addr_house1=8468&addr_house1_other=1&addr_place1=843733&addr_place1_other=%D0%EE%E4%E5%EE+++%C4%F0%E0%E9%E2&addr_since1=2007&addr_until1=1000000&addr_type2=10&addr_type2_other=%CA%E8%ED%EE%F2%E5%E0%F2%F0&addr_country2=1&addr_city2=2&addr_district2=128&addr_station2=170&addr_street2=290811&addr_street2_other=%C3%F0%E0%E6%E4%E0%ED%F1%EA%E8%E9+%EF%F0.&addr_house2=6968&addr_house2_other=41&addr_place2=20517&addr_place2_other=%C0%EA%E0%E4%E5%EC%E8%F7%E5%F1%EA%E8%E9&addr_since2=2008&addr_until2=1000000&addr_type3=50&addr_type3_other=%C3%E8%EF%E5%F0%EC%E0%F0%EA%E5%F2&addr_country3=1&addr_city3=2&addr_district3=127&addr_station3=225&addr_street3=290889&addr_street3_other=%C4%FB%E1%E5%ED%EA%EE+%F3%EB.&addr_house3=3637&addr_house3_other=28+%C2&addr_place3=12637475&addr_place3_other=%C0%F8%E0%ED%2C%CC%C5%C3%C0&addr_since3=1000000&addr_until3=2008&addr_type4=11&addr_type4_other=%C1%EE%F3%EB%E8%ED%E3&addr_country4=1&addr_city4=2&addr_district4=135&addr_station4=198&addr_street4=292220&addr_street4_other=%CC%EE%F1%EA%EE%E2%F1%EA%E8%E9+%EF%F0.&addr_house4=1902&addr_house4_other=111&addr_place4=10012&addr_place4_other=%CC-111&addr_since4=2007&addr_until4=0&addr_type5=49&addr_type5_other=%D1%F3%EF%E5%F0%EC%E0%F0%EA%E5%F2&addr_country5=1&addr_city5=2&addr_district5=128&addr_station5=170&addr_street5=293517&addr_street5_other=%D0%F3%F1%F2%E0%E2%E5%EB%E8+%F3%EB.&addr_house5=nil&addr_house5_other=%C2%E2%E5%E4%E8%F2%E5+%ED%EE%EC%E5%F0+%E4%EE%EC%E0&addr_place5=826970&addr_place5_other=%CA%E0%F0%F3%F1%E5%EB%FC&addr_since5=0&addr_until5=0&addr_type6=nil&addr_type6_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country6=1&addr_city6=nil&addr_since6=0&addr_until6=0&addr_type7=nil&addr_type7_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country7=1&addr_city7=nil&addr_since7=0&addr_until7=0&addr_type8=nil&addr_type8_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country8=1&addr_city8=nil&addr_since8=0&addr_until8=0&addr_type9=nil&addr_type9_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country9=1&addr_city9=nil&addr_since9=0&addr_until9=0&addr_type10=nil&addr_type10_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country10=1&addr_city10=nil&addr_since10=0&addr_until10=0&addr_type11=nil&addr_type11_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country11=1&addr_city11=nil&addr_since11=0&addr_until11=0&addr_type12=nil&addr_type12_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country12=1&addr_city12=nil&addr_since12=0&addr_until12=0&addr_type13=nil&addr_type13_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country13=1&addr_city13=nil&addr_since13=0&addr_until13=0&addr_type14=nil&addr_type14_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country14=1&addr_city14=nil&addr_since14=0&addr_until14=0&addr_type15=nil&addr_type15_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country15=1&addr_city15=nil&addr_since15=0&addr_until15=0&addr_type16=nil&addr_type16_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country16=1&addr_city16=nil&addr_since16=0&addr_until16=0&addr_type17=nil&addr_type17_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country17=1&addr_city17=nil&addr_since17=0&addr_until17=0&addr_type18=nil&addr_type18_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country18=1&addr_city18=nil&addr_since18=0&addr_until18=0&addr_type19=nil&addr_type19_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country19=1&addr_city19=nil&addr_since19=0&addr_until19=0&addr_type20=nil&addr_type20_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country20=1&addr_city20=nil&addr_since20=0&addr_until20=0&addr_type21=nil&addr_type21_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country21=1&addr_city21=nil&addr_since21=0&addr_until21=0&addr_type22=nil&addr_type22_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country22=1&addr_city22=nil&addr_since22=0&addr_until22=0&addr_type23=nil&addr_type23_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country23=1&addr_city23=nil&addr_since23=0&addr_until23=0&addr_type24=nil&addr_type24_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country24=1&addr_city24=nil&addr_since24=0&addr_until24=0&addr_type25=nil&addr_type25_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country25=1&addr_city25=nil&addr_since25=0&addr_until25=0&addr_type26=nil&addr_type26_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country26=1&addr_city26=nil&addr_since26=0&addr_until26=0&addr_type27=nil&addr_type27_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country27=1&addr_city27=nil&addr_since27=0&addr_until27=0&addr_type28=nil&addr_type28_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country28=1&addr_city28=nil&addr_since28=0&addr_until28=0&addr_type29=nil&addr_type29_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country29=1&addr_city29=nil&addr_since29=0&addr_until29=0&addr_type30=nil&addr_type30_other=%C2%FB%E1%E5%F0%E8%F2%E5+%F2%E8%EF&addr_country30=1&addr_city30=nil&addr_since30=0&addr_until30=0";
	$d = multicurl($d);

	$d[0]['url'] = "http://vkontakte.ru/profileEdit.php?page=personal";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."pe4.html";
	$d[0]['pst'] =
	"subm=1"
	."&hash=".$hash
	."&activities=%D4%EE%F2%EE%F1%E5%F1%F1%E8%FF%2C+%F4%EE%F2%EE%2C+%EA%EB%F3%E1%2C+%EF%EE%F0%F2%F4%EE%EB%E8%EE%2C+%E2%EF%E8%F1%EA%E8%2C+%EA%E0%F0%F2%FB%2C+%E4%F0%F3%E7%FC%FF%2C+%E4%F0%F3%E6%ED%EE%2C+%E2%E8%EF%2C+vip]"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vkontakte.ru/profileEdit.php?page=education";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."pe5.html";
	$d[0]['pst'] = "subm=1&hash=".$hash."&country=1&uni_city=2&other_city_name=%CD%E0%E7%E2%E0%ED%E8%E5+%E3%EE%F0%EE%E4%E0&university=56&other_university_name=%CD%E0%E7%E2%E0%ED%E8%E5+%E3%EE%F0%EE%E4%E0&faculty=231&chair=840&edu_form=1&edu_status=6&graduation=2005&country1=1&city1=2&school1=12&school1_type=0&s_start1=1989&s_finish1=1999&s_grad1=1999&s_class1=2&s_spec1=%F4%E8%E7-%EC%E0%F2&country2=1&city2=nil&s_start2=nil&s_finish2=nil&s_grad2=nil&s_class2=nil&s_spec2=&country3=1&city3=nil&s_start3=nil&s_finish3=nil&s_grad3=nil&s_class3=nil&s_spec3=&country4=1&city4=nil&s_start4=nil&s_finish4=nil&s_grad4=nil&s_class4=nil&s_spec4=&country5=1&city5=nil&s_start5=nil&s_finish5=nil&s_grad5=nil&s_class5=nil&s_spec5=&country6=1&city6=nil&s_start6=nil&s_finish6=nil&s_grad6=nil&s_class6=nil&s_spec6=&country7=1&city7=nil&s_start7=nil&s_finish7=nil&s_grad7=nil&s_class7=nil&s_spec7=";
	$d = multicurl($d);
	#************************
	/*
	unset($d[0]['pst']);
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."profile_hash.html";
	$d[0]['url'] = "http://vkontakte.ru/profile.php";
	$d = multicurl($d);
	list($hash)=search_infile($d[0]['fnm'], "activityhash", "value='", "'");
	echo "profile hash=".$hash."\n";
	$d[0]['url'] = "http://vkontakte.ru/profile.php";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."profile_status.html";
	$d[0]['pst'] = "setactivity=%D0%BF%D0%BE%D0%BC%D0%BE%D0%B3%D0%B0%D1%8E%20%D1%81%20%D0%BA%D0%BE%D0%BC%D0%BF%D0%BE%D0%BC!&activityhash=".$hash;
	$d = multicurl($d);
	*/

	unset($d[0]['pst']);
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."profile_photo_upload_hash.html";
	$d[0]['url'] = "http://vkontakte.ru/profileEdit.php?page=photo";
	$d = multicurl($d);
	list($hash)=search_infile($d[0]['fnm'], "upload.php", "action=\"", "\"");
	echo "profile photo hash=".$hash."\n";
	$d[0]['url'] = $hash;
	$d[0]['chk'] = 1; $d[0]['fnm'] = $path."profile_photo_upload.html";
	$profile_photo_filename = "pic/100/".rand(0, 99).".jpg";
	if($is_mk) { $profile_photo_filename = "pic/me.jpg"; }
	$d[0]['pst'] = array(
	"subm" => "1",
	"photo" => "@$profile_photo_filename"
	);

	$d = multicurl($d);
}


function get_indexes() {
	global $obj_curl;
	$obj_curl->url = "http://vkontakte.ru/index.php";
	$obj_curl->post = false;
	$obj_curl->method_main_curl();
}


function get_friends($lcm) {
	global $obj_curl, $temp_dir;
	list($num_friends) = search_infile($obj_curl->filename, "myfriends", "<b>", "</b>");
	if($num_friends == false) {
		$num_friends = 0; $friend_mess = "";
	} else {
		$obj_curl->url = "http://vkontakte.ru/friend.php?out=1";
		$obj_curl->filename = $temp_dir.$lcm."/friends.html";
		$obj_curl->post = false;
		$obj_curl->method_main_curl();
		$tmp_mess_arr = search_infile($obj_curl->filename, "msgOld", "<span>", "</span>");
		$friend_mess = to_utf($tmp_mess_arr[0]);
		$tmp_name_arr = search_infile($obj_curl->filename, "friendShownName", "\">", "</a>");
		$friend_name = to_utf($tmp_name_arr[0]);
	}
	if($num_friends) { echo "[".$num_friends." FRIENDS] [".$friend_name."] [".$friend_mess."]\n"; }
}


function get_groups($l) {
	global $obj_curl, $temp_dir;
	list($num_groups) = search_infile($obj_curl->filename, "groups.php", "<b>", "</b>");
	if($num_groups == false) {
		$num_groups = 0; $group_name = "";
	} else {
		$obj_curl->url = "http://vkontakte.ru/groups.php";
		$obj_curl->filename = $temp_dir.$l."/groups.html";
		$obj_curl->post = false;
		$obj_curl->method_main_curl();
		$group_name = search_infile($obj_curl->filename, "groupName", "\">", "<");
	}
	if($num_groups) {
		echo "[".$num_groups." GROUPS]\n"; eflush();
		$g=0;
		do {
			echo to_utf($group_name[$g])."\n"; eflush();
			$g++;
		} while ($g < count($group_name));
	}
}


function get_messages($i) {
	global $rcm_arr, $temp_dir;
	$path = $temp_dir."1real/".$rcm_arr[$i]."/";
	$d[0]['cuk'] = $path."cookie.txt";

	#************************
	unset($d[0]['pst']);
	$d[0]['url'] = "http://vkontakte.ru/";
	$index_filename = $path."index.html";
	$d[0]['chk'] = 1; $d[0]['fnm'] = $index_filename;
	$d = multicurl($d, 25000);
	list($num_messages) = search_infile($d[0]['fnm'], "mail.php?id=", " (<b>", "</b>)</a></li>");
	if($num_messages == FALSE) {
		$num_messages = 0; $message = "NO MESSAGES";
	} else {
		$d[0]['url'] = "http://vkontakte.ru/mail.php";
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."messages.html";
		$d = multicurl($d);

		$id_name_arr = search_infile($d[0]['fnm'], "newRow", "\">", "</a>", 13);
		$title_arr   = search_infile($d[0]['fnm'], "newRow", "<span 0>", "</span>", 19);
		$mess_arr    = search_infile($d[0]['fnm'], "newRow", "messageBody\">", "</a>", 20);
	}
	if($num_messages) {
		for($mi=0; $mi<count($mess_arr); $mi++) {
			$id_name_arr[$mi] = to_utf($id_name_arr[$mi]);
			$title_arr[$mi]   = to_utf($title_arr[$mi]);
			$mess_arr[$mi]    = to_utf($mess_arr[$mi]);
			echo "[".$num_messages." MESSAGES] [".$id_name_arr[$mi]."] [".$title_arr[$mi]."]\n".$mess_arr[$mi]."\n"; eflush();
		}
	}

	list($num_friends) = search_infile($index_filename, "myfriends", "<b>", "</b>");
	if($num_friends == false) {
		$num_friends = 0; $friend_mess = "";
	} else {
		$d[0]['url'] = "http://vkontakte.ru/friend.php?out=1";
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."friends.html";
		$d = multicurl($d, 25000);
		$tmp_mess_arr = search_infile($d[0]['fnm'], "msgOld", "<span>", "</span>");
		$friend_mess = to_utf($tmp_mess_arr[0]);
		$tmp_name_arr = search_infile($d[0]['fnm'], "friendShownName", "'>", "</a>");
		$friend_name = to_utf($tmp_name_arr[0]);
	}
	if($num_friends) { echo "[".$num_friends." FRIENDS] [".$friend_name."] [".$friend_mess."]\n"; }

	/*
	 list($num_proposals) = search_infile_left($index_filename, "matches.php", "Proposals (<b>", "</b>)");
	 if($num_proposals == false) {
		$num_proposals = 0; //$mess = "";
		} else {

		$d[0]['url'] = "http://vkontakte.ru/questions.php";
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."questions.html";
		$d = multicurl($d);
		$tmp_mess_arr = search_infile($d[0]['fnm'], "</b>)<span class='dividerSm", "(<b>+", "</b>)");
		$mess = to_utf($tmp_mess_arr[0]);
		$tmp_name_arr = search_infile($d[0]['fnm'], "friendShownName", "\">", "</a>");
		$name = to_utf($tmp_name_arr[0]);
			
		}
		if($num_proposals) { echo "[".$num_proposals." PROPOSALS]\n"; }
		list($num_questions) = search_infile($index_filename, "matches.php", "Questions (<b>", "</b>)</a>");
		if($num_questions == false) {
		$num_questions = 0; //$mess = "";
		} else {

		$d[0]['url'] = "http://vkontakte.ru/questions.php";
		$d[0]['chk'] = 1; $d[0]['fnm'] = $path."questions.html";
		$d = multicurl($d);
		$tmp_mess_arr = search_infile($d[0]['fnm'], "</b>)<span class='dividerSm", "(<b>+", "</b>)");
		$mess = to_utf($tmp_mess_arr[0]);
		$tmp_name_arr = search_infile($d[0]['fnm'], "friendShownName", "\">", "</a>");
		$name = to_utf($tmp_name_arr[0]);

		}
		if($num_questions) { echo "[".$num_questions." QUESTIONS]\n"; }
		*/
}



function get_topic_mess($i) {
	global $obj_curl, $temp_dir, $day, $lgm_arr, $t_arr;
	$l = $lgm_arr[$i];
	$obj_curl->post = false;
	for($ti=0; $ti<=2; $ti++) {
		$t = $t_arr[$i][$ti];
		$obj_curl->filename = $temp_dir.$l."/t".$t.".html";
		$obj_curl->url = "http://vkontakte.ru/board.php?act=topic&tid=".$t;
		$obj_curl->method_main_curl();
		$t_author_arr = search_infile($obj_curl->filename, "class=\"postAuthor\"", "<a href=\"", "</a>");
		$t_date_arr = search_infile($obj_curl->filename, "class=\"postAuthor\"", "<span class=\"timestamp\">", "</span>");
		$t_mess_arr = search_infile($obj_curl->filename, "class=\"postMessage\"", "\">", "</div>");

		for($mi=0; $mi<count($t_mess_arr); $mi++) {
			$t_author_arr[$mi] = to_utf($t_author_arr[$mi]);
			$t_date_arr[$mi] = to_utf($t_date_arr[$mi]);
			$t_mess_arr[$mi] = to_utf($t_mess_arr[$mi]);

			$t_author_arr[$mi] = substr($t_author_arr[$mi], strpos($t_author_arr[$mi], "\">")+2);

			$tmp = substr($t_date_arr[$mi], 0, strpos($t_date_arr[$mi], ",")); # парсим день отправки сообщения
			$tmp = substr($tmp, strpos($tmp, "on "));
			$messday =  preg_replace("/[^\d]/", NULL, $tmp);

			if($messday == $day) {
				echo "### ".$t_author_arr[$mi]." ### ".$t_date_arr[$mi]." ### \n";
				echo str_replace("<br>", "\n", html_entity_decode($t_mess_arr[$mi]))."\n";
			}
		}
	}
}


function get_wall($l) {

}


function get_group_wall($i) {
	global $obj_curl, $temp_dir, $lgm_arr, $group_arr, $day;
	$l = $lgm_arr[$i];
	$g = $group_arr[$i];
	$obj_curl->filename = $temp_dir.$l."/groupwall.html";
	$obj_curl->post = FALSE;
	$obj_curl->url = "http://vkontakte.ru/club".$g;
	$obj_curl->method_main_curl();

	$name_arr = search_infile($obj_curl->filename, "style=\"font-weight: bold;\">", "style=\"font-weight: bold;\">", "</a>");
	$mess_arr = search_infile($obj_curl->filename, "id=\"wPost", "\">", "</div>");
	$date_arr = search_infile($obj_curl->filename, "style=\"font-weight: bold;\">", "<small>", "</small>", 1);

	for($mi=0; $mi<count($mess_arr); $mi++) {
		$date_arr[$mi] = to_utf($date_arr[$mi]);
		$name_arr[$mi] = to_utf($name_arr[$mi]);
		$mess_arr[$mi] = to_utf($mess_arr[$mi]);
		$tmp = explode(",", $date_arr[$mi]);
		$founded = preg_replace("/[^\d]/", NULL, $tmp[0]);
		if($founded == $day) {
			echo "{{{ ".$name_arr[$mi]." }}}";
			echo " {{{ ".$date_arr[$mi]." }}}\n";
			echo str_replace("<br>", "\n", html_entity_decode($mess_arr[$mi]))."\n";
		} // else echo $tmp[0]."\n";
	}
}


function do_smsearch($threads = 10) {
	global $curr_time, $day_trigger, $is_debug, $scm_arr, $microtime, $table, $temp_dir;
	$dbcnx       = db_init();
	$total       = count($scm_arr);  # количество от 1
	$year_start  = 1980;
	$year_stop   = 1990;
	$year        = $year_start;
	$day_start   = 1;
	$day_stop    = 31;
	$day         = $day_start;
	$st          = 0;
	$st_max      = ($day_trigger == 1) ? 490 : 10000;
	$is_end      = 0;
	do { #  while($is_end == 0);
		for($l = 0; ( ($l < $total) && ($is_end == 0) ); $l += $threads) {  # не совсем правильно, т.к. не наблюдается полной заполности l в d
			unset($d);
			for($t = 0; ( ($t < $threads) && (($l + $t) < $total) && ($is_end == 0) ); $t++) {
				$st_beg[$t] = $st;
				switch($day_trigger) {
					case 0:
						$search_word   = "%F4%E8%ED%E0%ED%F1%FB"; #
						$d[$t]['url']  = "http://vkontakte.ru/search.php?act=quick&q=".$search_word."&st=".$st;
						break;
					case 1:
						$d[$t]['url']  = "http://vkontakte.ru/search.php?subm=1&act=adv";
						$d[$t]['url'] .= "&sex=1"; # ищем девчёнок
						$d[$t]['url'] .= "&bday_day=".$day."&bday_year=".$year;
						$d[$t]['url'] .= "&uni_city=2&online=1&o=1&st=".$st;
						break;
				}
				$d[$t]['chk'] = 1;
				$d[$t]['cuk'] = $temp_dir."1search/".$scm_arr[$l+$t]."/cookie.txt";
				$d[$t]['fnm'] = $temp_dir."1search/".$scm_arr[$l+$t]."/wsearch-".$st.".html";
				echo "l=".$l." t=".$t."\t".$d[$t]['url']."\n";
					
				$st += 10;
				if($st > $st_max) {
					$st = 0;
					switch($day_trigger) {
						case 0:
							$is_end = 1;
							break;
						case 1:
							if($day < $day_stop) {
								$day++;
							} else {
								if($year < $year_stop) {
									$day    = $day_start;
									$year++;
								} else {
									$is_end = 1;
									#break; # выход из for $t
								}
							}
					}  # switch($day_trigger)
				}  # if($st > $st_max)
			}  # for($t = 0; ( ($t < $threads) && (($l + $t) < $total) ); $t++)
			//print_r($d);

			$d = multicurl($d);

			for($t = 0; $t < count($d); $t++) {
				if($is_debug) { echo "login=".($l+$t)." \tl=".$l."\tt=".$t."\t".$d[$t]['url']."\n"; }
				list($tmp) = search_infile($d[$t]['fnm'], "<strong>", "<strong>", "</strong>");
				$founded =  preg_replace("/[^\d]/", NULL, to_utf($tmp));
				if($is_debug) { echo "founded=".$founded."\n"; }
				$ids_page_arr = search_infile($d[$t]['fnm'], "mail.php?act=write&to=", "&to=", "\"");
				if(isset($ids_page_arr)) {
					$names_page_arr = search_infile($d[$t]['fnm'], "<dt>Name:</dt>", "\">", "</", 2);
					for($ipi = 0; $ipi < count($ids_page_arr); $ipi++) { # ids page i
						$ids_page_arr[$ipi] = preg_replace("/[^\d]/", NULL, $ids_page_arr[$ipi]);
						$names_page_arr[$ipi] = to_utf($names_page_arr[$ipi]);
						echo "{".$t."} [".($st_beg[$t] + $ipi)."] [".$ids_page_arr[$ipi]."] ".$names_page_arr[$ipi];
						if($ids_page_arr[$ipi] > 0) {
							$tmp_query = "SELECT id_vk FROM `".$table."` WHERE id_vk=".$ids_page_arr[$ipi];
							$id_result  = mysql_query($tmp_query);
							$id_counter = 0;
							unset($id);
							while($id_row = mysql_fetch_row($id_result)) {
								list($id) = $id_row;
								$id_counter++; // количество id вконтакте
							}
							if(!isset($id)) {
								$tmp_query  = "INSERT INTO `".$table."` ";
								$tmp_query .= "(id, id_vk, flag, year, day, curr_time, send_time, name) VALUES ";
								$tmp_query .= "(NULL, '$ids_page_arr[$ipi]', '1', ";
								if($day_trigger == 1) { $tmp_query .= "'$year', '$day', "; } else {	$tmp_query .= "NULL, NULL, "; }
								$tmp_query .= "'$curr_time', NULL, '$names_page_arr[$ipi]')";
								mysql_query($tmp_query);
							} else {
								echo "\tID ALREADY FOUND!!!";
							}
						} else {  # if($ids_page_arr[$ipi] > 0) {
							echo "\t|||BAD ID|||";
						}         # if($ids_page_arr[$ipi] > 0) {
						echo "\n";
					} # for($ipi = 0; $ipi < count($ids_page_arr); $ipi++)
				} else {  # if(isset($ids_page_arr))
					if($is_debug) { echo "st=".$st_beg[$t]."\tlcm=".$scm_arr[$l+$t]."\tERROR\n"; }
					list($is_nomatches) = search_infile($d[$t]['fnm'], "<div class=\"fallBack\">", "there were ", " found", 1);
					if(isset($is_nomatches)) {
						if($is_nomatches == "no matches") {
							if($is_debug) { echo $is_nomatches."\n";  eflush(); }
							$st = $st_max; # таким способом выходим из цикла (не совсем правильно, так как добавляется ещё один лишний проход
						}
					}
				}         # if(isset($ids_page_arr))
					
				$is_toofast = search_infile($d[$t]['fnm'], "simpleHeader", "\">", "</");
				if(isset($is_toofast)) {
					$string = substr($is_toofast[0], 0, -1);
					if($string == "Too fast") {
						echo $string."\n";
						echo "need to change:   ".$scm_arr[$l+$t]."]----------------------\n"; eflush();
					}
				}
			}
		}
	} while($is_end == 0);
	echo "DONE!\n";
}


function do_lmsend_invites($threads=10) {
	global $max_chip, $prx_arr, $temp_dir, $curr_time, $gid, $is_event, $is_need_send_offline, $microtime, $mysql_query, $lcm_arr, $scm_arr, $s, $table;

	$chip       = 0; # change ip
	
	$total      = count($lcm_arr);  # количество от 1
	$dbcnx      = db_init();
	$id_result  = mysql_query($mysql_query);
	
	
	$id_counter = 0;
	while($id_row = mysql_fetch_row($id_result)) {
		list($id_vk, $flag, $year, $day, $name) = $id_row;
		$ids  [$id_counter] = $id_vk;
		$flags[$id_counter] = $flag;
		$years[$id_counter] = $year;
		$days [$id_counter] = $day;
		$names[$id_counter] = $name;
		$id_counter++; // количество id вконтакте
	}
	//print_r($ids);

	if(isset($ids)) {
		$i = 0;
		if($is_event == 1) {
			# получаем страничку, чтобы потом не было проблем с отправкой сообщения якобы с неактивного аккаунта
			unset($d);
			$d[0]['chk'] = 1;
			$d[0]['url'] = "http://vkontakte.ru/index.php";
			$d[0]['prx'] = $prx_arr[$s];
			$d[0]['cuk'] = $temp_dir.$lcm_arr[$s]."/cookie.txt";
			$d[0]['fnm'] = $temp_dir.$lcm_arr[$s]."/s.html";
			$d = multicurl($d);
			$prx_arr[$s]  = $d[$t]['prx'] ;
		}

		while($i < count($ids)) {
			unset($d);
			for($t = 0; (($t < $threads) && (($i+$t) < count($ids)) ); $t++) {
				$d[$t]['chk'] = 1;
				$d[$t]['url'] = "http://vkontakte.ru/search.php";
				$d[$t]['pst'] = "q=".$ids[$i+$t]."&act=quick&n=0";
				$d[$t]['cuk'] = $temp_dir."1search/".$scm_arr[$t]."/cookie.txt";
				$d[$t]['fnm'] = $temp_dir."1search/".$scm_arr[$t]."/online_check-".($i+$t)."-".$ids[$i+$t].".html";
			}
			$max_curr_t = $t;
			//echo "data="; print_r($d);
			$d = multicurl($d);
			$curr_time = date("Y-m-d H:i:s");

			$is_onl_tr = 0;
			unset($online);
			for($t = 0; $t < $max_curr_t; $t++) {
				switch($is_need_send_offline) {
					case 0:
						list($is_online) = search_infile($d[$t]['fnm'],
			                                 "<dd class=\"matches\"><div><span></span></div></dd>",
			                                 "<span class='bbb'>",
			                                 "</span>");
						echo ($i+$t)." \t".$ids[$i+$t]."    \t";
						if(strcmp($is_online, "Online") == 0) {
							$online[$t]    = 1;
							$is_onl_tr     = 1;
							echo "ONLINE";
						} else {
							$online[$t]    = 0;
							echo "OFFLINE";
						}
						echo "\t".$days[$i+$t]."\tlogin=".$t." \t".$scm_arr[$t]."\tt=".$t;
						echo "\t".$d[$t]['pst']."  \t".$names[$i+$t]."\n";
						unset($is_online); # нужно на всякий случай, т.к. в файле не всегда могут быть верные данные
						mysql_query("UPDATE `".$table."` SET curr_time= '".$curr_time."' WHERE id_vk=".$ids[$i+$t]);
						break;

					case 1:
						$online[$t]        = 1;
						$is_onl_tr         = 1;
				}
			}

			if($is_onl_tr == 1) {
				for($t = 0; $t < $max_curr_t; $t++) {
					if($online[$t] == 1) {
						unset($d);
						$d[0]['chk'] = 1;
						$d[0]['url']     = "http://vkontakte.ru/groups.php?act=ajaxinv&gid=".$gid;
						if($is_event == 1) {
							$d[0]['url'] = "http://vkontakte.ru/events.php?act=ajaxinv&gid=".$gid;
						}
						$d[0]['pst'] = "id=".$ids[$i+$t];
						$d[0]['prx'] = $prx_arr[$s];
						$d[0]['cuk'] = $temp_dir.$lcm_arr[$s]."/cookie.txt";
						$d[0]['fnm'] = $temp_dir.$lcm_arr[$s]."/send-".$ids[$i+$t].".html";
						//echo "send="; print_r($d);
						$d = multicurl($d);
						$prx_arr[$s] = $d[0]['prx'];

						$send_time = date("Y-m-d H:i:s");
						list($inv_mess) = search_infile($d[0]['fnm'], "<p id='msg'>", "<p id='msg'>", "</p>");
						$inv_mess = to_utf($inv_mess);
						list($is_captcha) = search_infile($d[0]['fnm'], "captcha", "", "");
						if(strpos($is_captcha, "captcha")) { echo "!!!CAPTCHA!!!\n"; exit; }
						
						if(strcmp(preg_replace("/[^\d]/", NULL, $inv_mess), 40) != 0) {
							if($is_event == 1) {
								switch($inv_mess) {
									case "Invitation is sent.":
										$flag = 2;
										break;
									case "Only friends can invite this user to events.":
										$flag = 3;
										break;
									case "Invitation has been already sent.":
										$flag = 4;
										break;
									case "User forbade to invite him to events.":
										$flag = 5;
										break;
									case "This person is already a member.":
										$flag = 7;
										break;
									default:
										echo "inv_mess=".$inv_mess."\n";
								}
							} else {
								switch($inv_mess) {
									case "Invitation has been sent.":
										$flag = 2;
										break;
									case "Only friends are allowed to invite this person to join groups.":
										$flag = 3;
										break;
									case "Invitation has already been sent.":
										$flag = 4;
										break;
									case "You can not invite this person to join groups.":
										$flag = 5;
										break;
									case "This person is already a member.":
										$flag = 7;
										break;
									default:
										echo "inv_mess=".$inv_mess."\n";
								}
							}
							mysql_query("UPDATE `".$table."` SET flag='".$flag."', send_time= '".$send_time."' WHERE id_vk=".$ids[$i+$t]);
							echo "[".($i+$t)."] [".$ids[$i+$t]."] [".$s."] [".$lcm_arr[$s]."] [".$years[$i+$t]."-".$days[$i+$t]."] [".$names[$i+$t]."] ".$inv_mess."\n"; eflush();
						} else {
							if($s < $total-1) {
								echo "\ns=".$s."\t40 LIMIT\n";
								$s++; // нельзя пригласить больше 40
								$i -= $max_curr_t;
								$t = 0;
								if($chip < $max_chip) {
									$chip++; 								
								} else {
									$chip = 0;
									system("./chip.sh");
								}
								
								if($is_event == 1) {
									unset($d);
									$d[0]['chk'] = 1;
									$d[0]['url'] = "http://vkontakte.ru/index.php";
									$d[0]['prx'] = $prx_arr[$s];
									$d[0]['cuk'] = $temp_dir.$lcm_arr[$s]."/cookie.txt";
									$d[0]['fnm'] = $temp_dir.$lcm_arr[$s]."/s.html";
									$d = multicurl($d);
									$prx_arr[$s]  = $d[0]['prx'];
								}
								break;  # выходим из for($t = 0; $t < $max_curr_t; $t++)
							} else {
								mysql_close($dbcnx);
								exit("\n\tLCM FINISHED - 40 LIMIT !!!\n");
							}
						}  # if(strcmp(preg_replace("/[^\d]/", NULL, $inv_mess), 40) != 0)
					}  # if($online[$t] == 1)
				}  # for($t = 0; $t < $max_curr_t; $t++)
			}  # if($is_onl_tr == 1)
			$i += $max_curr_t;
		}  # while($i < count($ids))
	}  # if(isset($ids))
	echo "!!! ALL ID'S FINISHED !!!\n";
	mysql_close($dbcnx);
}

?>
